package com.lap.analysis.tools;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;

import com.lap.analysis.exception.ConfigError;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class PropUtil {

  private PropUtil() {}

  public static Properties getProp(String file) {
    Properties prop = new Properties();
    try (InputStream in = new ClassPathResource(file).getInputStream()) {
      prop.loadFromXML(in);
      return prop;
    } catch (IOException e) {
      log.error(e.getLocalizedMessage(), e);
      throw new ConfigError("Read config.xml error: " + e.getLocalizedMessage());
    }
  }

  public static Properties getProp() {
    return getProp("test-config.xml");
  }
}
